
/*
 * Copyright 2008 Friendster Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 
 
 * Unless required by applicable law or agreed to in writing, 
 * software distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and limitations under the License.
*/

using System;
using System.Text;
using System.Collections;

namespace Friendster.Service
{
    /// <summary>
    /// This is an abstract class of key=>value pair dictionary elements,
    /// all data representation classes inharits from this.
    /// </summary>
    public abstract class FriendsterEntity
    {
        // Fields
        private Hashtable _entityState;

        // Methods
        internal FriendsterEntity(Hashtable entityState)
        {
            if (entityState == null)
            {
                entityState = new Hashtable();
            }
            this._entityState = entityState;
        }

        /// <summary>
        /// Returns the templated value of given key from hashtable.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        protected T GetState<T>(string key)
        {
            object obj2 = this._entityState[key];
            if (obj2 == null)
            {
                return default(T);
            }
            return (T)obj2;
        }

        /// <summary>
        /// Returns the object value of specified index from the dictionary.
        /// </summary>
        /// <param name="key"></param>
        protected object this[string key]
        {
            get
            {
                return this._entityState[key];
            }
            set
            {
                this._entityState[key] = value;
            }
        }

    }
}
